package com.wall.haven.config;

import com.wall.haven.service.impl.BanImageServiceImpl;
import com.wall.haven.service.impl.SystemConfigServiceImpl;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class SystemConfigCache {

    @Resource
    private SystemConfigServiceImpl systemConfigService;
    @Resource
    private BanImageServiceImpl banImageService;

    /**
     * 授权验证key
     */
    private String secretKey;
    
    /**
     * 接口是否返回
     */
    private boolean showSecretKey;

    /**
     * 鉴权token有效时长
     */
    private long secretValidTime;

    /**
     * 默认头像
     */
    private String defaultAvatar;

    /**
     * RSA 公钥
     */
    private String rsaPublicKey;

    /**
     * RSA 私钥
     */
    private String rsaPrivateKey;

    /**
     * AES加密KEY
     */
    private String aesKey;
    
    /**
     * 是否开放nsfw内容
     */
    private boolean nsfw;

    /**
     * 初始化缓存配置到内存
     */
    public void load(){
        this.secretKey = systemConfigService.getSecretKey();
        this.showSecretKey = systemConfigService.isShowSecretKey();
        this.secretValidTime = systemConfigService.getSecretValidTime();
        this.defaultAvatar = systemConfigService.getDefaultAvatar();
        this.rsaPublicKey = systemConfigService.getRsaPublicKey();
        this.rsaPrivateKey = systemConfigService.getRsaPrivateKey();
        this.aesKey = systemConfigService.getAesKey();
        this.nsfw = systemConfigService.isNsfw();
        banImageService.init();
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public long getSecretValidTime() {
        return secretValidTime;
    }

    public void setSecretValidTime(long secretValidTime) {
        this.secretValidTime = secretValidTime;
    }

    public String getDefaultAvatar() {
        return defaultAvatar;
    }

    public void setDefaultAvatar(String defaultAvatar) {
        this.defaultAvatar = defaultAvatar;
    }

    public String getRsaPublicKey() {
        return rsaPublicKey;
    }

    public void setRsaPublicKey(String rsaPublicKey) {
        this.rsaPublicKey = rsaPublicKey;
    }

    public String getRsaPrivateKey() {
        return rsaPrivateKey;
    }

    public void setRsaPrivateKey(String rsaPrivateKey) {
        this.rsaPrivateKey = rsaPrivateKey;
    }

    public String getAesKey() {
        return aesKey;
    }

    public void setAesKey(String aesKey) {
        this.aesKey = aesKey;
    }

    public boolean isShowSecretKey() {
        return showSecretKey;
    }

    public void setShowSecretKey(boolean showSecretKey) {
        this.showSecretKey = showSecretKey;
    }

    public boolean isNsfw() {
        return nsfw;
    }

    public void setNsfw(boolean nsfw) {
        this.nsfw = nsfw;
    }
}
